var index = 0
let value_type_desc = '魅力值'
$('.ranking-list-item-2').hide()
let user_id = common.getUrlParam('user_id')
getRank(user_id)

$('.value_type').html(value_type_desc)
$(document).on('click', '.switch-item', function () {
    $('.switch-item').removeClass('active')
    $(this).addClass('active')
    index = $(this).index()
    $('.ranking-list-box').hide()
    $('.ranking-list-box-' + index).show()
    switch (index) {
        case 0:
            value_type_desc = '魅力值'
            $('.ranking-list-item-0').show()
            $('.ranking-list-item-2').hide()
            break;
        case 1:
            value_type_desc = '财富值'
            $('.ranking-list-item-2').show()
            $('.ranking-list-item-0').hide()
            break;
    }
    $('.value_type').html(value_type_desc)
})


$(".back-top>img").on("click", function () {
    returnTop()
})


function getRank(user_id) {
    common.getRequest({user_id:user_id}, common.API.index, function (res) {

        let charm = res.data.charm;
        let wealth = res.data.wealth;
        console.log(charm.list[0])
        //昨日榜单
        let yesterday_charm = charm.pre_day_top_three
        let yesterday_wealth = wealth.pre_day_top_three

        let user_img = 'static/images/heart.png'

        $.each(yesterday_charm, function (i, v) {
            if (!common.isEmpty(v.images)) {
                let vimg = v.images;
                user_img = vimg[0]
            }
            if (i == 0) {
                //超级
                $('.lucky-star-head-charm').append(' <div class="star-head">\n' +
                    '                        <img src="' + user_img + '" alt="">\n' +
                    '                    </div>\n' +
                    '                    <p class="lucky-name">' + v.nickname + '</p>\n' +
                    '                    <p class="lucky-id">ID:' + v.user_uid + '</p>\n' +
                    '                    <div class="decoration">\n' +
                    '                        <img src="static/images/decoration.png" alt="">\n' +
                    '                    </div>')
            }
            if (i == 15 || i == 25 || i == 35 || i == 45) {
                $('.every-day').append('  <div class="every-day-item">\n' +
                    '                    <div class="every-day-head">\n' +
                    '                        <img src="' + user_img + '" alt="">\n' +
                    '                    </div>\n' +
                    '                    <p class="lucky-name">' + v.nickname + '</p>\n' +
                    '                    <p class="lucky-id">ID:' + v.user_uid + '</p>\n' +
                    '                    <div class="every-day-decoration">\n' +
                    '                        <img src="static/images/star-yellow.png" alt="">\n' +
                    '                    </div>\n' +
                    '                </div>')
            }
        })

        $.each(yesterday_wealth, function (i, v) {
            if (!common.isEmpty(v.images)) {
                let vimg = v.images;
                user_img = vimg[0]
            }
            if (i == 0) {
                //超级
                $('.lucky-star-head-wealth').append(' <div class="star-head">\n' +
                    '                        <img src="' + user_img + '" alt="">\n' +
                    '                    </div>\n' +
                    '                    <p class="lucky-name">' + v.nickname + '</p>\n' +
                    '                    <p class="lucky-id">ID:' + v.user_uid + '</p>\n' +
                    '                    <div class="decoration">\n' +
                    '                        <img src="static/images/decoration.png" alt="">\n' +
                    '                    </div>')
            }
            if (i == 15 || i == 25 || i == 35 || i == 45) {
                $('.every-day').append('  <div class="every-day-item">\n' +
                    '                    <div class="every-day-head">\n' +
                    '                        <img src="' + user_img + '" alt="">\n' +
                    '                    </div>\n' +
                    '                    <p class="lucky-name">' + v.nickname + '</p>\n' +
                    '                    <p class="lucky-id">ID:' + v.user_uid + '</p>\n' +
                    '                    <div class="every-day-decoration">\n' +
                    '                        <img src="static/images/star-yellow.png" alt="">\n' +
                    '                    </div>\n' +
                    '                </div>')
            }
        })


        //今日榜单
        let charm_user = charm.curr_user_is_online
        let is_online = '距上榜';
        if (charm_user.is_online == 1) {
            is_online = '距离上一名';
        }

        $('.ranking-list-item-0').append('<div class="item-num">\n' +
            '            <p class="not">' + charm_user.is_online_desc + '</p>\n' +
            '        </div>\n' +
            '        <div class="item-head">\n' +
            '            <div class="item-head-img">\n' +
            '                <img src="' + charm_user.image + '" alt="">\n' +
            '            </div>\n' +
            '        </div>\n' +
            '        <div class="item-information">\n' +
            '            <p class="item-name">' + charm_user.nickname + '</p>\n' +
            '        </div>\n' +
            '        <div class="item-value">\n' +
            '            <div class="item-number">\n' +
            '                <p>' + charm_user.ranking_diff_value + '</p>\n' +
            '            </div>\n' +
            '            <p class="distance">' + is_online + '</p>\n' +
            '        </div>')
        $('.ranking-list-box-0').empty()

        $.each(charm.list, function (i, v) {
            let back_div = ''
            let num = i + 1;
            let num_class = ''
            let hea_img = ''
            if (num < 4) {
                num_class = 'num-' + num;
            }
            let diff_rank = v.ranking_diff_value

            let user_img = 'static/images/heart.png'
            if (!common.isEmpty(v.images)) {
                let vimg = v.images;
                user_img = vimg[0]
            }
            if (num == 1 || num == 16 || num == 26 || num == 36 || num == 46) {
                console.log(num)
                back_div = 'ranking-list-item-active'
            }
            $('.ranking-list-box-0').append('<div class="ranking-list-item  ' + back_div + '">\n' +
                '                        <div class="item-num">\n' +
                '                            <p class="' + num_class + '">' + num + '</p>\n' +
                '                        </div>\n' +
                '                        <div class="item-head charm-head">\n' +
                '                            <div class="item-head-img">\n' +
                '                                <img src="' + user_img + '" alt="">\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="item-information">\n' +
                '                            <p class="item-name">' + v.nickname + '</p>\n' +
                '                            <p class="item-id">ID:' + v.user_uid + '</p>\n' +
                '                        </div>\n' +
                '                        <div class="item-value charm-value-' + num + '">\n' +
                '                        </div>\n' +
                '                    </div>')
            if (num == 1) {
                $('.charm-value-' + num).prepend('<div class="item-number"><p>超级幸运星</p><img src="static/images/star.png"></div>')
            } else {
                $('.charm-value-' + num).prepend('<div class="item-number"><p>' + diff_rank + '</p> <p>距上名</p></div>')
            }


            if (num < 4) {
                hea_img = 'static/images/hat-' + num + '.png';
                $('.charm-head').append('<div class="item-head-decoration">\n' +
                    '                                <img src="' + hea_img + '">\n' +
                    '                            </div>')
            }
        })

        let wealth_user = wealth.curr_user_is_online
        let w_is_online = '距上榜';
        if (wealth_user.is_online == 1) {
            w_is_online = '距离上一名';
        }
        $('.ranking-list-item-2').append('<div class="item-num">\n' +
            '            <p class="not">' + wealth_user.is_online_desc + '</p>\n' +
            '        </div>\n' +
            '        <div class="item-head">\n' +
            '            <div class="item-head-img">\n' +
            '                <img src="' + wealth_user.image + '" alt="">\n' +
            '            </div>\n' +
            '        </div>\n' +
            '        <div class="item-information">\n' +
            '            <p class="item-name">' + wealth_user.nickname + '</p>\n' +
            '        </div>\n' +
            '        <div class="item-value">\n' +
            '            <div class="item-number">\n' +
            '                <p>' + wealth_user.ranking_diff_value + '</p>\n' +
            '            </div>\n' +
            '            <p class="distance">' + w_is_online + '</p>\n' +
            '        </div>')
        $('.ranking-list-box-1').empty()
        $.each(wealth.list, function (i, v) {
            let num = i + 1;
            let num_class = ''
            let hea_img = ''
            if (num < 4) {
                num_class = 'num-' + num;
            }
            let diff_rank = v.ranking_diff_value

            let user_img = 'static/images/heart.png'
            if (!common.isEmpty(v.images)) {
                let vimg = v.images;
                user_img = vimg[0]
            }
            let back_div = ''

            if (num == 1 || num == 16 || num == 26 || num == 36 || num == 46) {
                back_div = 'ranking-list-item-active'
            }
            $('.ranking-list-box-1').append('<div class="ranking-list-item  ' + back_div + '">\n' +
                '                        <div class="item-num">\n' +
                '                            <p class="' + num_class + '">' + num + '</p>\n' +
                '                        </div>\n' +
                '                        <div class="item-head charm-head">\n' +
                '                            <div class="item-head-img">\n' +
                '                                <img src="' + user_img + '" alt="">\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="item-information">\n' +
                '                            <p class="item-name">' + v.nickname + '</p>\n' +
                '                            <p class="item-id">ID:' + v.user_uid + '</p>\n' +
                '                        </div>\n' +
                '                        <div class="item-value wealth-value-' + num + '">\n' +
                '                        </div>\n' +
                '                    </div>')
            if (num == 1) {
                $('.wealth-value-' + num).prepend('<div class="item-number"><p>超级幸运星</p><img src="static/images/star.png"></div>')
            } else {
                $('.wealth-value-' + num).prepend('<div class="item-number"><p>' + diff_rank + '</p> <p>距上名</p></div>')
            }
            if (num < 4) {
                hea_img = 'static/images/hat-' + num + '.png';
                $('.wealth-head').append('<div class="item-head-decoration">\n' +
                    '                                <img src="' + hea_img + '">\n' +
                    '                            </div>')
            }
        })


    })
}


// 返回顶部
function returnTop() {
    document.body.scrollTop = 0;
    document.documentElement.scrollTop = 0;
}
